<template>
	<view class="my">
		<!-- 登录 -->
		<view class="center-login" v-if="data.nickname">
			<view class="center-login-left" @click="goUser">
				<view class="header">
					<image class="img" src="http://8.130.66.190/img/Felinus.jpg"></image>
				</view>
				<view class="name">{{ data.nickname }}</view>
			</view>
		</view>
		<view class="center" v-else>
			<view class="login" @click="goEdit"><button>登录</button></view>
		</view>

		<!-- 订单 -->
		<view class="indent">
			<view class="indent-text">
				<view class="left">
					<uni-icons type="calendar" color="green" size="30"></uni-icons>
					已付款的订单
				</view>
				<view class="right">
					<uni-icons type="right" size="30"></uni-icons>
				</view>
			</view>
		</view>

		<!-- 设置 -->
		<view class="set-list">
			<view class="indent-text first">
				<view class="left">
					<uni-icons type="gear" color="green" size="30"></uni-icons>
					通用设置
				</view>
				<view class="right">
					<uni-icons type="right" size="30"></uni-icons>
				</view>
			</view>
		</view>
		<view class="set-list">
			<view class="indent-text">
				<view class="left">
					<uni-icons type="chat-filled" color="green" size="30"></uni-icons>
					吐槽产品
				</view>
				<view class="right">
					<uni-icons type="right" size="30"></uni-icons>
				</view>
			</view>
		</view>
		<view class="set-list">
			<view class="indent-text">
				<view class="left">
					<uni-icons type="info" color="green" size="30"></uni-icons>
					关于我们
				</view>
				<view class="right">
					<uni-icons type="right" size="30"></uni-icons>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
import {
	reqLogin,
	reqGetUserInfo
} from '../../api/index.js'
export default {
	data() {
		return {
			data: {
				nickname: '', //用户昵称
				headimgurl: '', //用户头像
			}
		}
	},
	mounted() {
		this.getUserInfo()
	},
	methods: {
		// 跳转到登录
		goEdit() {
			//获取用户授权成功标识--code
			uni.login({
				//授权成功的回调
				success: (res) => {
					this.login(res.code)
				},
			})
		},
		// 点击登录
		async login(code) {
			const result = await reqLogin(code);
			if (result.code == 200) {
				//本地存储持久化存储数据
				uni.setStorageSync('TOKEN', result.data.token);
				uni.redirectTo({
					url: '/pages/login/index',
				})
			}
		},
		// 获取用户信息
		async getUserInfo() {
			const result = await reqGetUserInfo();
			if (result.code === 200) {
				this.data.nickname = result.data.nickname,
					this.data.headimgurl = result.data.headimgurl
			}
		},
		goUser(){
			uni.navigateTo({
				url:'/pages/my/user/index'
			})
		}
	}
}
</script>

<style scoped lang="scss">
.my {
	.center-login {
		background-color: #eee;
		width: 100%;
		height: 150rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;

		.center-login-left {
			display: flex;
			align-items: center;
			.header {
				width: 100rpx;
				height: 100rpx;
				margin-left: 40rpx;
				margin-right: 20rpx;

				.img {
					width: 100%;
					height: 100%;
					border-radius: 50%;

				}
			}
		}
		.icon{
			margin-right: 14rpx;
		}

	}

	.center {
		display: flex;
		justify-content: center;
		padding: 80rpx 140rpx;
		background-color: #eee;

		.login {
			width: 200rpx;
		}

		.sign {
			width: 200rpx;
		}
	}

	.indent {
		background-color: white;
		width: 100%;
		height: 100rpx;
		line-height: 100rpx;
		margin-bottom: 30rpx;

		.indent-text {
			margin-left: 30rpx;
			display: flex;

			.left {
				width: 90%;
			}

			.right {
				width: 10%;
			}
		}
	}

	.set-list {
		background-color: white;
		width: 100%;
		height: 100rpx;
		line-height: 100rpx;

		.indent-text {
			margin-left: 30rpx;
			display: flex;
			margin-bottom: 4rpx;
			border-bottom: 1px solid black;
			border-top: 1px solid black;

			.left {
				width: 90%;
			}

			.right {
				width: 10%;
			}
		}
	}
}
</style>